﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Skill.Ode;
using Skill.Ode.Joints;

namespace Samples.Common
{
    public class Ode : IDisposable
    {
        public DWorld World { get; private set; }
        public DJointGroup Group { get; private set; }

        #region Constructor
        public Ode()
        {
            if (!DOde.IsInitialized)
            {
                DOde.Initialize2(DOde.DInitializeOdeFlags.ManualThreadCleanup);
                DOde.AllocateDataForThread(DOde.DAllocateOdeDataFlags.MaskAll);
            }
            World = new DWorld();
            Group = new DJointGroup();
        }
        #endregion

        #region IDisposable Members

        public void Dispose()
        {
            if (World != null)
                World.Dispose();
            if (Group != null)
                Group.Dispose();
            World = null;
            Group = null;
            if (DOde.IsInitialized)
                DOde.Close();
        }

        #endregion
    }
}
